/* eslint-disable react-hooks/exhaustive-deps */
import React, { useState, useEffect } from 'react';
import { Form } from 'antd';
import { ArrowLeftOutlined } from '@ant-design/icons';
import { useHistory } from 'react-router-dom';
import qs from 'qs';
import Collapse from '@/components/collapse';
import UserInfo from '@/components/user-update/userInfo';
import ParkingLotInfo from '@/components/user-update/parkingLotInfo';
import ParkingLotExtraInfo from '@/components/user-update/parkingLotExtraInfo';
import FileExtraInfo from '@/components/user-update/fileExtraInfo';
import UserAdvice from '@/components/user-advice';
import RequestApi from '@/utils/request';
import css from './index.scss';

/**
 * 我的备案整改功能
 * -
 */
export default () => {
	const history = useHistory();
	const [form] = Form.useForm();
	const [parkLotManagerBaseInfoFile, setParkLotManagerBaseInfoFile] = useState(); // 经营管理者基本信息文件
	const [parkLotBaseInfoFile, setParkLotBaseInfoFile] = useState(); // 停车场设施-基本信息文件
	const [parkLotAttachmentsInfoFile, setParkLotAttachmentsInfo] = useState(); // 附件文件
	const [advice, setAdvice] = useState(); // 整改意见数据
	function getAllData() {
		const search = qs.parse(history.location.search, { ignoreQueryPrefix: true });
		const { id, stage } = search;
		RequestApi.connection('get', `/parkLotRecordTask/getReformInfo/${id}/${stage}`).then((response) => {
			const allAdvice = {
				name: response.data.row.name,
				auditReason: response.data.row.auditReason,
				status: response.data.row.status,
				resultAssignTasks: response.data.row.resultAssignTasks,
			};
			setAdvice(allAdvice);
			const data = response.data.row.parkLotInfo;
			setParkLotManagerBaseInfoFile(data.parkLotManagerBaseInfoDTO);
			setParkLotBaseInfoFile(data.parkLotBaseInfoDTO);
			setParkLotAttachmentsInfo(data.parkLotAttachmentsInfoDTO);
			const parkLotManagerBaseInfoData = data.parkLotManagerBaseInfoDTO;
			const parkLotBaseInfoData = data.parkLotBaseInfoDTO;
			const districtName = [parkLotBaseInfoData.districtName];
			const positionProperty = parkLotBaseInfoData.positionProperty.split(',');
			const parkLotSettingInfoData = data.parkLotSettingInfoDTO;
			const guideSystemType =
				parkLotSettingInfoData.guideSystemType === null ? [] : parkLotSettingInfoData.guideSystemType.split(',');
			const solidParkType =
				parkLotSettingInfoData.solidParkType === null ? [] : parkLotSettingInfoData.solidParkType.split(',');
			const fireFighting =
				parkLotSettingInfoData.fireFighting === null ? [] : parkLotSettingInfoData.fireFighting.split(',');
			const intelligentElectricChargeSystem =
				parkLotSettingInfoData.intelligentElectricChargeSystem === null
					? []
					: parkLotSettingInfoData.intelligentElectricChargeSystem.split(',');
			const signage = parkLotSettingInfoData.signage === null ? [] : parkLotSettingInfoData.signage.split(',');
			const parkLotAttachmentsInfo = data.parkLotAttachmentsInfoDTO;
			form.setFieldsValue({
				// 经营管理者基本信息
				name: parkLotManagerBaseInfoData.name,
				manageOrgName: parkLotManagerBaseInfoData.manageOrgName,
				manageOrgPhone: parkLotManagerBaseInfoData.manageOrgPhone,
				propertyOrgName: parkLotManagerBaseInfoData.propertyOrgName,
				propertyOrgPhone: parkLotManagerBaseInfoData.propertyOrgPhone,
				propertyOrgRelation: parkLotManagerBaseInfoData.propertyOrgRelation,
				managerName: parkLotManagerBaseInfoData.managerName,
				managerPhone: parkLotManagerBaseInfoData.managerPhone,
				isCharge: parkLotManagerBaseInfoData.isCharge,
				isParkFeeDiscount: parkLotManagerBaseInfoData.isParkFeeDiscount,
				businessLicense: parkLotManagerBaseInfoData.businessLicense,
				propertyRight: parkLotManagerBaseInfoData.propertyRight,
				permissionRight: parkLotManagerBaseInfoData.permissionRight,
				recomendation: parkLotManagerBaseInfoData.recomendation,

				// 停车场设施-基本信息
				districtName,
				address: parkLotBaseInfoData.address,
				entranceLongitude: parkLotBaseInfoData.entranceLongitude,
				entranceLatitude: parkLotBaseInfoData.entranceLatitude,
				parkLevel: parkLotBaseInfoData.parkLevel,
				parkLotType: parkLotBaseInfoData.parkLotType,
				landUseNature: parkLotBaseInfoData.landUseNature,
				planParkCount: parkLotBaseInfoData.planParkCount,
				parkLotScale: parkLotBaseInfoData.parkLotScale,
				saleParkCount: parkLotBaseInfoData.saleParkCount,
				externalParkCount: parkLotBaseInfoData.externalParkCount,
				externalParkCountDesc: parkLotBaseInfoData.externalParkCountDesc,
				parkArea: parkLotBaseInfoData.parkArea,
				parkAreaDesc: parkLotBaseInfoData.parkAreaDesc,
				noObstacleParkCount: parkLotBaseInfoData.noObstacleParkCount,
				chaegePileParkCount: parkLotBaseInfoData.chaegePileParkCount,
				parkLotRommType: parkLotBaseInfoData.parkLotRommType,
				microParkCount: parkLotBaseInfoData.microParkCount,
				dischargeParkCount: parkLotBaseInfoData.dischargeParkCount,
				mechanicalParkCount: parkLotBaseInfoData.mechanicalParkCount,
				commonParkCount: parkLotBaseInfoData.commonParkCount,
				entranceExitScale: parkLotBaseInfoData.entranceExitScale,
				entranceExitLaneScale: parkLotBaseInfoData.entranceExitLaneScale,
				positionProperty,
				confirmationOfCompletion: parkLotBaseInfoData.confirmationOfCompletion,
				parkLotList: parkLotBaseInfoData.parkLotList,
				chargePilesEvidentialMaterial: parkLotBaseInfoData.chargePilesEvidentialMaterial,

				// 停车场设施-附属设施
				guideSystemType,
				haveCarWash: parkLotSettingInfoData.haveCarWash,
				netAndSignalPercent: parkLotSettingInfoData.netAndSignalPercent,
				solidParkType,
				fireFighting,
				publicToiletCount: parkLotSettingInfoData.publicToiletCount,
				haveParkSystem: parkLotSettingInfoData.haveParkSystem,
				isPreSaveDataInterface: parkLotSettingInfoData.isPreSaveDataInterface,
				intelligentElectricChargeSystem,
				monitorSystemPercent: parkLotSettingInfoData.monitorSystemPercent,
				haveLightingFacility: parkLotSettingInfoData.haveLightingFacility,
				haveUrgeLightingSystem: parkLotSettingInfoData.haveUrgeLightingSystem,
				haveVentilationSystem: parkLotSettingInfoData.haveVentilationSystem,
				haveParkPosition: parkLotSettingInfoData.haveParkPosition,
				haveRoadHarden: parkLotSettingInfoData.haveRoadHarden,
				haveBarrier: parkLotSettingInfoData.haveBarrier,
				wallAndCeillingIsDecoration: parkLotSettingInfoData.wallAndCeillingIsDecoration,
				signage,
				signageOther: parkLotSettingInfoData.signageOther,
				spotFeePublicBrand: parkLotSettingInfoData.spotFeePublicBrand,
				chargePileCount: parkLotSettingInfoData.chargePileCount,

				// 相关附件
				applicationRecordForm: parkLotAttachmentsInfo.applicationRecordForm,
				emergencyResponsePlan: parkLotAttachmentsInfo.emergencyResponsePlan,
				manageOperateMaintainProject: parkLotAttachmentsInfo.manageOperateMaintainProject,
				others: parkLotAttachmentsInfo.others,
				parkLotSettingList: parkLotAttachmentsInfo.parkLotSettingList,
				prospectForm: parkLotAttachmentsInfo.prospectForm,
				serviceAndSafeSystem: parkLotAttachmentsInfo.serviceAndSafeSystem,
				trafficOrganisationChart: parkLotAttachmentsInfo.trafficOrganisationChart,
			});
		});
	}
	useEffect(() => {
		getAllData();
	}, []);
	function result(v1, v2) {
		console.log(v1, v2);
		form.setFieldsValue({
			longitude: v1,
			latitude: v2,
		});
	}
	return (
		<div className={css.app}>
			<div className={css.header}>
				<span className={css.back_myRecord}>
					<ArrowLeftOutlined />
				</span>
				<span>我的备案</span>
				<span className={css.tip}>特别提醒: 由于上传资料过多，填写过程请及时暂存,以免上传失效重复填写。</span>
			</div>
			<div className={css.content}>
				<Form name="form" form={form} layout="vertical">
					<Collapse
						form1={<UserInfo parkLotManagerBaseInfoFile={parkLotManagerBaseInfoFile} form={form} />}
						form2={<ParkingLotInfo result={result} parkLotBaseInfoFile={parkLotBaseInfoFile} form={form} />}
						form3={<ParkingLotExtraInfo form={form} />}
						form4={<FileExtraInfo parkLotAttachmentsInfoFile={parkLotAttachmentsInfoFile} form={form} />}
					/>
					<UserAdvice advice={advice} form={form} />
				</Form>
			</div>
		</div>
	);
};
